Skip to content

Conversation

keewis
Copy link
Member

@keewis keewis commented Aug 10, 2025

This is a reimplementation of #143 (and #203), based on inspect.signature objects to deal with the classification of args and kwargs.

Once complete, we'll be able to define functions like this:

from pint_xarray import expects, unit_registry as ureg


@expects(None, "m", ureg.s, {None: "kg", "lat": "rad"}, return_value={None: None})
def func(a, b, c, d):
    ...

and have the decorator convert any arguments to the appropriate units, or raise an error if the unit spec does not match the argument (either because the units are incompatible, or because the spec requires an xarray object but the argument is a scalar / plain array / quantity).

@keewis
Copy link
Member Author

keewis commented Aug 10, 2025

cc @TomNicholas, in case you're still interested (it's been 3-4 years)

@keewis keewis merged commit d9ca190 into xarray-contrib:main Aug 15, 2025
15 checks passed
@keewis keewis deleted the expects branch August 15, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@ureg.wraps decorator
1 participant